package com.hongxun.budget.ui.view.ys;

import android.app.Fragment;
import android.widget.EditText;
import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.view.BaseView;
import com.hongxun.budget.utils.GreenDaoManager;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.budget.utils.TestingUtils;
import com.hongxun.greenentity.ys.EPointEntity;

/**
 * Created by admin on 2018/8/27.
 */

public class YsXiaHuDianView extends BaseView {


    EditText xiahushu;
    TextView xiahushu_name;


    public YsXiaHuDianView(Fragment fragment) {
        super(fragment);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.view_ys_xiahudian;
    }

    @Override
    protected void initView() {
        super.initView();
        xiahushu = getView(R.id.xiahushu);
        xiahushu_name = getView(R.id.xiahushu_name);
        if (SPUtils.get(context, "point_name", "").equals("开关柜")) {
            xiahushu_name.setText("出线数");
        }
    }

    EPointEntity d;

    @Override
    public boolean save(EPointEntity d) {
        String xhs = xiahushu.getText().toString().trim();
        if (!TestingUtils.isEmpty(context, xhs, SPUtils.get(context, "point_name", "").equals("开关柜") ? "出线数" : "下户数"))
            return false;
        if (SPUtils.get(context, "point_name", "").equals("开关柜")) d.setPPOutLine(Integer.parseInt(xhs));
        else d.setPPHucount(Integer.parseInt(xhs));//下户数
        this.d = d;
        return true;
    }

    @Override
    public void insertDB() {
        GreenDaoManager.getInstance().getmDaoSession().getEPointEntityDao().insertOrReplace(d);
    }

    @Override
    public void updateInit(Object o) {
        EPointEntity d = (EPointEntity) o;
        if (SPUtils.get(context, "point_name", "").equals("开关柜")) {
            xiahushu.setText(d.getPPOutLine() + "");
        } else
            xiahushu.setText(d.getPPHucount() + "");
    }

    @Override
    public void initDefault() {
        EPointEntity d = GreenDaoManager.getInstance().getmDaoSession().getEPointEntityDao().load(SPUtils.get(context, "UUID", "").toString());
        if (d != null) updateInit(d);
    }
}
